package org.linlinjava.litemall.db.service;

import com.github.yulichang.base.MPJBaseServiceImpl;
import org.linlinjava.litemall.db.dao.LumierePayMemberUserMapper;
import org.linlinjava.litemall.db.domain.LitemallOrderGoodsProperty;
import org.linlinjava.litemall.db.domain.LumierePayMemberUser;
import org.linlinjava.litemall.db.domain.LumierePayMemberUserExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LumierePayMemberUserService extends MPJBaseServiceImpl<LumierePayMemberUserMapper,LumierePayMemberUser> {

    @Resource
    private LumierePayMemberUserMapper lumierePayMemberUserMapper;

    public List<LumierePayMemberUser> list(LumierePayMemberUserExample example){
        return lumierePayMemberUserMapper.selectByExample(example);
    }

    public LumierePayMemberUser findById(Integer id) {
        return lumierePayMemberUserMapper.selectByPrimaryKey(id);
    }

    public void add(LumierePayMemberUser lumierePayMember){
        lumierePayMemberUserMapper.insert(lumierePayMember);
    }

    public void update(LumierePayMemberUser lumierePayMember){
        lumierePayMemberUserMapper.updateByPrimaryKeySelective(lumierePayMember);
    }

    public void delete(Integer payMemberId){
        lumierePayMemberUserMapper.logicalDeleteByPrimaryKey(payMemberId);
    }
    
    public Integer countByMemberId(LumierePayMemberUserExample example){
       return (int)lumierePayMemberUserMapper.countByExample(example);
    }

    public List<LumierePayMemberUser> listUsers(Integer userId,Integer memberId){
        LumierePayMemberUserExample example = new LumierePayMemberUserExample();
        if(memberId != null){
            example.or().andDeletedEqualTo(false).andUserIdEqualTo(userId).andPayMemberIdEqualTo(memberId).andEndTimeGreaterThan(LocalDateTime.now());
        }else{
            example.or().andDeletedEqualTo(false).andUserIdEqualTo(userId).andEndTimeGreaterThan(LocalDateTime.now());
        }
        return lumierePayMemberUserMapper.selectByExample(example);
    }

    public List<LumierePayMemberUser> listByUserName(String username,Integer memberId){
        LumierePayMemberUserExample example = new LumierePayMemberUserExample();
        if(memberId != null){
            example.or().andDeletedEqualTo(false).andUserNameEqualTo(username).andPayMemberIdEqualTo(memberId);
        }else{
            example.or().andDeletedEqualTo(false).andUserNameEqualTo(username);
        }
        return lumierePayMemberUserMapper.selectByExample(example);
    }

    public List<LumierePayMemberUser> listMemberByUserId(Integer userId){
        LumierePayMemberUserExample example = new LumierePayMemberUserExample();
        example.or().andDeletedEqualTo(false).andUserIdEqualTo(userId).andEndTimeGreaterThan(LocalDateTime.now());

        return lumierePayMemberUserMapper.selectByExample(example);
    }

    public List<LumierePayMemberUser> listMemberUserByMemberId(List<Integer> memberIds){
        LumierePayMemberUserExample example = new LumierePayMemberUserExample();
        example.or().andDeletedEqualTo(false).andPayMemberIdIn(memberIds).andEndTimeGreaterThan(LocalDateTime.now());

        return lumierePayMemberUserMapper.selectByExample(example);
    }

    public List<LumierePayMemberUser> listUserNormal(){
        LumierePayMemberUserExample example = new LumierePayMemberUserExample();
        example.or().andDeletedEqualTo(false).andEndTimeGreaterThan(LocalDateTime.now());

        return  lumierePayMemberUserMapper.selectByExample(example);
    }


}
